home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * MacZoop - "the framework for the rest of us"
- *
- *
- *
- * FileMgrUtils.c -- file utilities
- *
- *
- *
- *
- *
- * © 1998, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
- #include "FileMgrUtils.h"
- #include "MacZoop.h"
-
-
- /*****************************************************************************/
- // Static methods obtained from MoreFiles- code provided by Apple DTS.
- /*****************************************************************************/
-
- #pragma mark ----- File Manager Utilities -----
-
- /*****************************************************************************/
-
- pascal OSErr GetDirectoryID(short vRefNum,
- long dirID,
- StringPtr name,
- long *theDirID,
- Boolean *isDirectory)
- {
- CInfoPBRec pb;
- Str31 tempName;
- OSErr error;
-
- /* Protection against File Sharing problem */
- if ( (name == NULL) || (name[0] == 0) )
- {
- tempName[0] = 0;
- pb.hFileInfo.ioNamePtr = tempName;
- pb.hFileInfo.ioFDirIndex = -1; /* use ioDirID */
- }
- else
- {
- pb.hFileInfo.ioNamePtr = name;
- pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
- }
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- error = PBGetCatInfoSync(&pb);
- *isDirectory = (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0;
- *theDirID = (*isDirectory) ? pb.dirInfo.ioDrDirID : pb.hFileInfo.ioFlParID;
- return ( error );
- }
-
- /*****************************************************************************/
-
- pascal OSErr FSpGetDirectoryID(const FSSpec *spec,
- long *theDirID,
- Boolean *isDirectory)
- {
- return ( GetDirectoryID(spec->vRefNum, spec->parID, (StringPtr)spec->name,
- theDirID, isDirectory) );
- }
-
-
- /*****************************************************************************/
-
- short GetSFCurVol()
- {
- return -(LMGetSFSaveDisk());
- }
-
- /*****************************************************************************/
-
- long GetSFCurDir()
- {
- return LMGetCurDirStore();
- }
-
-
- Boolean GetFullPathname(FSSpec* aSpec, Str255 pathname)
- {
- // returns the full pathname for the file spec passed. If the file does not exist, this
- // returns FALSE, if it does, it returns TRUE.
-
- DirInfo blk;
- Str255 dirName;
- OSErr theErr;
- Boolean result = TRUE;
-
- pathname[0] = 0;
-
- blk.ioDrParID = aSpec->parID;
- blk.ioNamePtr = dirName;
-
- do
- {
- blk.ioVRefNum = aSpec->vRefNum;
- blk.ioFDirIndex = -1;
- blk.ioDrDirID = blk.ioDrParID;
-
- theErr = PBGetCatInfoSync((CInfoPBPtr) &blk );
-
- if (theErr)
- {
- result = FALSE;
- break;
- }
-
- ConcatPStrings(dirName,"\p:");
- pStrInsert(pathname,dirName);
- }
- while(blk.ioDrDirID != 2);
- if (result)
- ConcatPStrings(pathname,aSpec->name);
- return result;
- }
-
- /*****************************************************************************/
-
-
- OSErr MakeCanonFSSpec ( FSSpec *spec )
- {
- OSErr err ;
-
- err = FSMakeFSSpec( spec->vRefNum,
- spec->parID,
- spec->name,
- spec ) ;
- return noErr ;
- }
-
- /*****************************************************************************/
-
- Boolean SameFile ( FSSpec *spec1, FSSpec *spec2 )
- {
- if (spec1->vRefNum != spec2->vRefNum)
- return false;
- if (spec1->parID != spec2->parID)
- return false;
- if ( !EqualString( spec1->name, spec2->name, false, true ) )
- return false;
- return true;
- }
-
- /*****************************************************************************/
-
- void pStrInsert(StringPtr dest,StringPtr src)
- {
- // inserts <src> at the beginning of <dest>
-
- BlockMoveData(dest + 1,dest + *src + 1,*dest);
- BlockMoveData(src + 1,dest + 1,*src);
- *dest += *src;
- }
-
- /*****************************************************************************/
-
-